<template>
    <el-row class="madp-stepcomplete">
        <el-col :span="6">
            <div class="madp-stepcomplete-left">
                <div class="madp-selectbox">
                    <i class="el-icon-s-custom" :style="{'background': theme}"></i>
                    <el-select
                        v-model="userValue"
                        @change="getTousers"
                        filterable
                        placeholder="请选择"
                    >
                        <el-option
                            v-for="item in userList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </div>

                <el-tabs
                    v-model="activeType"
                    class="madp-tabs-left"
                    type="border-card"
                    @tab-click="changeType"
                >
                    <el-input
                        class="madp-search"
                        v-model.trim="inputType"
                        placeholder="按名称搜索"
                        @change="getTousers"
                    ></el-input>
                    <el-tab-pane
                        v-for="item  in typeList"
                        :key="item.id"
                        :label="item.name"
                        :name="item.id"
                    >
                        <ul v-for="item in personList" :key="item.toUserId">
                            <li class="madp-person">
                                <div class="madp-person-img">
                                    <img :src="item.avatar" />
                                </div>
                                <span>{{item.name}}</span>
                            </li>
                        </ul>
                    </el-tab-pane>
                    <!-- <el-tab-pane label="外部"
                                    name="1">
                        外部
                    </el-tab-pane>
                    <el-tab-pane label="群聊"
                                    name="2">
                        群聊
                    </el-tab-pane>-->
                </el-tabs>
            </div>
        </el-col>
        <el-col :span="18">
            <div class="madp-stepcomplete-right">
                <el-tabs
                    v-model="activeName"
                    class="madp-tabs"
                    type="border-card"
                    @tab-click="handleClick"
                >
                    <el-form :inline="true" ref="refForm" :model="refForm" class="madp-search-form">
                        <el-form-item>
                            <el-input v-model.trim="refForm.name" placeholder="请输入搜索名称"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-date-picker
                                v-model="refForm.date"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                            ></el-date-picker>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="handleSearch">搜索</el-button>
                            <el-button @click="clearForm">清空</el-button>
                        </el-form-item>
                    </el-form>

                    <el-tab-pane label="所有" name="first">所有</el-tab-pane>
                    <el-tab-pane label="文本" name="1">文本</el-tab-pane>
                    <el-tab-pane label="图片" name="2">图片</el-tab-pane>
                    <el-tab-pane label="图文" name="13">图文</el-tab-pane>
                    <el-tab-pane label="音频" name="4">音频</el-tab-pane>
                    <el-tab-pane label="视频" name="5">视频</el-tab-pane>
                    <el-tab-pane label="小程序" name="seventh">小程序</el-tab-pane>
                    <el-tab-pane label="文件" name="eighth">文件</el-tab-pane>
                </el-tabs>
            </div>
        </el-col>
    </el-row>
</template>
<script>
import { mapGetters } from "vuex";
import {
    tousers, // 会话对象列表
    fromusers, //下拉列表
    workMessage // 会话内容存档 - 列表
} from "@/api/enterprise/message-archiving.js";
export default {
    props: [],
    computed: {
        ...mapGetters(["theme"])
    },
    data() {
        return {
            personList: [],
            typeList: [
                {
                    name: "内部",
                    id: "0"
                },
                {
                    name: "外部",
                    id: "1"
                },
                {
                    name: "群聊",
                    id: "2"
                }
            ],
            refForm: {
                name: "",
                date: ""
            },
            inputType: "",
            userList: [],
            userValue: "",
            activeType: "0",
            activeName: "first"
        };
    },
    mounted() {
        this.getFromusers();
    },
    methods: {
        getWorkMessage() {
            console.log("this.refForm.date", this.refForm.date);
            let data = {
                content: "",
                current: 1,
                size: 10,
                dateTimeStart: this.refForm.date[0],
                dateTimeEnd: this.refForm.date[1],
                toUserId: this.userValue, //聊天对象Id
                toUserType: this.activeType,
                type: this.activeName,
                workEmployeeId: this.userValue //员工ID
            };
            workMessage(data).then((res) => {
                if (res.data && res.data.code == 0) {
                    this.userList = res.data.data;
                    console.log("getWorkMessage", res);
                }
            });
        },
        getFromusers() {
            let data = {
                name: this.inputType
            };
            fromusers(data).then((res) => {
                if (res.data && res.data.code == 0) {
                    this.userList = res.data.data;
                    console.log("getFromusers", res);
                }
            });
        },
        getTousers() {
            let data = {
                workEmployeeId: this.userValue,
                toUsertype: this.activeType,
                name: this.inputType
            };
            tousers(data).then((res) => {
                if (res.data && res.data.code == 0) {
                    this.personList = res.data.data.records;
                    console.log("getTousers", res);
                }
            });
        },
        handleSearch() {},
        clearForm() {
            this.$refs.refForm.resetFields();
        },
        handleClick(tab, event) {
            console.log(tab, event);
            this.getWorkMessage();
        },
        changeType(tab, event) {
            console.log(tab, event);
            this.getTousers();
        }
    }
};
</script>
<style lang="scss" scoped>
.madp-person {
    width: 100%;
    height: 90px;
    display: flex;
    align-items: center;
    img {
        border-radius: 8px;
        width: 50px;
        margin-right: 10px;
    }
}
.madp-person-box {
    border-radius: 8px;
    width: 50px;
    height: 50px;
    overflow: hidden;
    display: flex;
    align-items: center;
}
.madp-search-form {
    display: flex;
    justify-content: flex-end;
}
/deep/ .el-date-editor .el-range-separator {
    width: 25px !important;
}

.madp-search {
    margin: 8px 0;
}
.madp-selectbox {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 5px;
    padding-right: 10px;
}
.el-icon-s-custom {
    font-size: 40px;
    width: 50px;
    height: 50px;
    text-align: center;
    color: #fff;
    line-height: 50px;
    border-radius: 50%;
    margin-right: 5px;
}
.madp-stepcomplete {
    background: #fff;
    border-radius: 4px;
    padding: 10px;
    margin: 0 10px;
}
.madp-tabs {
    height: 80vh;
}
.madp-tabs-left {
    height: calc(80vh - 60px);
}
.madp-stepcomplete-left {
    border: 1px solid #ccc;
    margin-right: 20px;
}
.madp-stepcomplete-left /deep/.el-tabs--border-card {
    border: none;
    border-top: 1px solid #dcdfe6;
}
.madp-stepcomplete-right {
    border: 1px solid #ccc;
}
/deep/.el-tabs__nav-scroll {
    display: flex !important;
    align-items: center !important;
}
/deep/.el-tabs__item {
    flex: 1 1 33.33%;
}
</style>
